var t = require("../../../@babel/runtime/helpers/objectWithoutProperties"), a = require("../../../@babel/runtime/helpers/defineProperty"), o = [ "url" ], e = getApp();

Page({
    data: {
        iconOption: [ {
            icon: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/warehouse-farm/cabbage.png",
            name: "菜",
            width: "256rpx",
            bottom: "420rpx",
            left: "32rpx",
            right: "auto",
            text: "bottom"
        }, {
            icon: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/warehouse-farm/eggs.png",
            name: "肉蛋",
            width: "216rpx",
            bottom: "508rpx",
            right: "60rpx",
            left: "auto",
            text: "top",
            textTop: "0rem"
        }, {
            icon: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/warehouse-farm/well.png",
            name: "水",
            width: "132rpx",
            bottom: "632rpx",
            right: "208rpx",
            left: "auto",
            text: "top",
            textTop: "-65rpx",
            zIndex: 1
        }, {
            icon: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/warehouse-farm/milk.png",
            name: "牛奶",
            width: "316rpx",
            bottom: "684rpx",
            left: "0",
            right: "auto",
            text: "bottom"
        }, {
            icon: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/warehouse-farm/seasoning.png",
            name: "调料",
            width: "168rpx",
            bottom: "284rpx",
            left: "28rpx",
            right: "auto",
            text: "bottom"
        }, {
            icon: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/warehouse-farm/Rice.png",
            name: "大米",
            width: "160rpx",
            bottom: "544rpx",
            left: "0",
            right: "auto",
            text: "bottom"
        }, {
            icon: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/warehouse-farm/flour.png",
            name: "面粉",
            width: "160rpx",
            bottom: "360rpx",
            right: "60rpx",
            left: "auto",
            text: "bottom"
        }, {
            icon: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/warehouse-farm/liquor.png",
            name: "酒",
            width: "124rpx",
            bottom: "248rpx",
            left: "188rpx",
            right: "auto",
            text: "bottom"
        }, {
            icon: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/warehouse-farm/delivery.png",
            name: "快递仓",
            width: "176rpx",
            bottom: "796rpx",
            left: "368rpx",
            right: "auto",
            text: "top",
            textTop: "32rpx"
        } ],
        showAnnouncement: !1,
        showDynamic: !1,
        showRank: !1,
        showReward: !1,
        info: {},
        gift: {},
        markid: null,
        rank_loading: !1,
        rank_finished: !1,
        rank_refreshing: !1,
        rank_page: 1,
        rank_list: [],
        rank_self: {},
        dynamic_loading: !1,
        dynamic_finished: !1,
        dynamic_refreshing: !1,
        dynamic_page: 1,
        dynamic_list: [],
        dynamic_self: {},
        todayDynamic: [],
        beforeDynamic: [],
        shareInfo: {}
    },
    onLoad: function(t) {
        t.gapid && this.setData({
            markid: t.gapid
        });
    },
    getData: function() {
        var t = this, a = {};
        this.data.markid && (a.gift_key = this.data.markid);
        var o = e.getNetAddresss("plugin.warehouse.frontend.controllers.center.index");
        e._postNetWork({
            url: o,
            data: a,
            success: function(a) {
                var o = a.data;
                1 == o.result ? t.setData({
                    info: o.data,
                    gift: o.data.gift || {},
                    showReward: !(!o.data.gift || !o.data.gift.judge),
                    shareInfo: o.data.share_info
                }) : wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getPopupData: function(t) {
        var o = this, n = "plugin.warehouse.frontend.controllers.center.rank";
        "dynamic_" == t && (n = "plugin.warehouse.frontend.controllers.center.dynamic-state"), 
        this.data["".concat(t, "loading")] = !0;
        var i = e.getNetAddresss(n);
        e._postNetWork({
            url: i,
            data: {
                page: this.data["".concat(t, "page")]
            },
            success: function(e) {
                var n = e.data;
                if (1 == n.result) {
                    var i, r = o.data["".concat(t, "list")];
                    if (o.setData((a(i = {}, t + "self", n.data.self), a(i, t + "refreshing", !1), i)), 
                    o.data["".concat(t, "page")] = o.data["".concat(t, "page")] + 1, o.data["".concat(t, "loading")] = !1, 
                    n.data.list.current_page == n.data.list.last_page && (o["".concat(t, "finished")] = !0), 
                    "dynamic_" == t) 1 == o.data["".concat(t, "page")] && (o.data.todayDynamic = [], 
                    o.data.beforeDynamic = []), n.data.list.data.forEach(function(t) {
                        o.isToday(t.created_at) ? o.data.todayDynamic.push(t) : o.data.beforeDynamic.push(t);
                    }), o.setData({
                        todayDynamic: o.data.todayDynamic,
                        beforeDynamic: o.data.beforeDynamic
                    }); else o.setData(a({}, t + "list", r.concat(n.data.list.data)));
                } else wx.showToast({
                    icon: "none",
                    title: n.msg,
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    cloneReward: function() {
        this.setData({
            showReward: !1
        }), wx.reLaunch({
            url: "/packageI/warehouseFarm/warehouseFarmIndex/warehouseFarmIndex"
        });
    },
    isToday: function(t) {
        return new Date(t).toDateString() === new Date().toDateString();
    },
    RefreshList: function(t) {
        var a = t.target.dataset.tag;
        this.data["".concat(a, "loading")] = !0, this.data["".concat(a, "page")] = 1, this.data["".concat(a, "list")] = [], 
        this.data["".concat(a, "finished")] = !1, this.data.todayDynamic = [], this.data.beforeDynamic = [], 
        this.getPopupData(a);
    },
    LoadList: function(t) {
        var a = t.target.dataset.tag;
        this.data["".concat(a, "finished")] || this.data["".concat(a, "loading")] || this.getPopupData(a);
    },
    openPopup: function(t) {
        var o = t.currentTarget.dataset;
        if (o.tag) {
            var e = o.tag;
            "showDynamic" == e ? this.getPopupData("dynamic_") : "showRank" == e && this.getPopupData("rank_"), 
            this.setData(a({}, e, o.set));
        }
    },
    toUrl: function(t) {
        var a = t.currentTarget.dataset || {};
        this.wxRouterLink(a);
    },
    wxRouterLink: function(a) {
        var e = "", n = a.url, i = t(a, o);
        Object.keys(i).forEach(function(t) {
            "" !== i[t] && (e += t + "=" + i[t] + "&");
        }), "" !== n && wx.navigateTo({
            url: n + "?" + e.slice(0, -1)
        });
    },
    onReady: function() {},
    onShow: function() {
        this.setData({
            showReward: !1
        }), this.getData();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        return {
            title: this.data.shareInfo.title,
            imageUrl: this.data.shareInfo.thumb
        };
    }
});